<?php
/**
 * product_info header_php.php 
 *
 * @package page
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: header_php.php 6963 2007-09-08 02:36:34Z drbyte $
 */

  // This should be first line of the script:
  $zco_notifier->notify('NOTIFY_HEADER_START_PRODUCT_INFO');

  require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));

  // if specified product_id is disabled or doesn't exist, ensure that metatags and breadcrumbs don't share inappropriate information
  $sql = "select count(*) as total
          from " . TABLE_PRODUCTS . " p, " .
                   TABLE_PRODUCTS_DESCRIPTION . " pd
          where    p.products_status = '1'
          and      p.products_id = '" . (int)$_GET['products_id'] . "'
          and      pd.products_id = p.products_id
          and      pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
  $res = $db->Execute($sql);
  if ( $res->fields['total'] < 1 ) {
    unset($_GET['products_id']);
    unset($breadcrumb->_trail[sizeof($breadcrumb->_trail)-1]['title']);
    header('HTTP/1.1 404 Not Found');
  }

  // ensure navigation snapshot in case must-be-logged-in-for-price is enabled
  if (!$_SESSION['customer_id']) {
    $_SESSION['navigation']->set_snapshot();
  }

  // AUCTION SITE ATTRIBUTES EDIT
  // build query
  $products_query = "SELECT products_weight, products_length, products_width, products_height, products_diameter, products_dim_type, products_weight_type, products_actual_weight FROM " . TABLE_PRODUCTS . " WHERE products_id = " . (int)$_GET['products_id'] . " LIMIT 1";
  // execute query
  $products = $db->Execute($products_query);
  // store variables
  $products_length = $products->fields['products_length'];
  $products_width = $products->fields['products_width'];
  $products_height = $products->fields['products_height'];
  $products_diameter = $products->fields['products_diameter'];
  $products_weight = $products->fields['products_weight'];
  $products_actual_weight = $products->fields['products_actual_weight'];
  $products_dim_type = strtolower($products->fields['products_dim_type']);
  $products_weight_type = strtolower($products->fields['products_weight_type']);
  // create conversions
  if (SHOW_PRODUCT_INFO_CONVERSIONS == 1) {
    if ($products_weight_type == 'kgs') {
      $products_weight2 = round($products_weight * 2.20462262, 2);
      $products_actual_weight2 = round($products_actual_weight * 2.20462262, 2);
      $products_weight_type2 = 'lbs';
    } else {
      $products_weight2 = round($products_weight * 0.45359237, 2);
      $products_actual_weight2 = round($products_actual_weight * 0.45359237, 2);
      $products_weight_type2 = 'kgs';
    }
    if ($products_dim_type == 'cm') {
      $products_dim_type2 = 'in';
      $conversion = 0.393700787;
    } else {
      $products_dim_type2 = 'cm';
      $conversion = 2.54;
    }
    if (SHOW_PRODUCT_INFO_SMALLER_UNITS == 1) { 
      if ($products_weight_type == 'kgs') {
        $products_weight_type = 'g';
        $products_weight_type2 = 'oz';
        $products_weight = $products_weight * 1000;
        $products_weight2 = $products_weight2 * 16;
        $products_actual_weight = $products_actual_weight * 1000;
        $products_actual_weight2 = $products_actual_weight2 * 16;
      } else {
        $products_weight_type = 'oz';
        $products_weight_type2 = 'g';
        $products_weight = $products_weight * 0.0625;
        $products_weight2 = $products_weight2 * 0.001;
        $products_actual_weight = $products_actual_weight * 0.0625;
        $products_actual_weight2 = $products_actual_weight2 * 0.001;
      }
    } 
    $products_weight_display = TEXT_PRODUCT_WEIGHT . $products_weight . $products_weight_type . '/' . $products_weight2 . $products_weight_type2;
    $products_actual_weight_display = TEXT_PRODUCTS_ACTUAL_WEIGHT . $products_actual_weight . $products_weight_type . '/' . $products_actual_weight2 . $products_weight_type2;
    $products_dim_display = TEXT_PRODUCT_DIMENSIONS . ($products_length > 0 ? TEXT_PRODUCTS_LENGTH . $products_length . $products_dim_type . ' (' . round($products_length * $conversion, 1) . $products_dim_type2 . ') ' : '') . ($products_width > 0 ? TEXT_PRODUCTS_WIDTH . $products_width . $products_dim_type . ' (' . round($products_width * $conversion, 1) . $products_dim_type2 . ') ' : '') . ($products_height > 0 ? TEXT_PRODUCTS_HEIGHT . $products_height . $products_dim_type . ' (' . round($products_height * $conversion, 1) . $products_dim_type2 . ')' : '');
    $products_diameter_display = TEXT_PRODUCTS_DIAMETER . ($products_diameter > 0 ? $products_diameter . $products_dim_type . ' (' . round($products_diameter * $conversion, 1) . $products_dim_type2 . ') ' : '');
  } else {
    
    if (SHOW_PRODUCT_INFO_SMALLER_UNITS == 1) { 
      if ($products_weight_type = 'kgs') {
        $products_weight_type = 'g';
        $products_weight = $products_weight * 1000;
      } else {
        $products_weight_type = 'oz';
        $products_weight = $products_weight * 0.0625;
      }
    } 
    $products_weight_display = TEXT_PRODUCT_WEIGHT .  $products_weight . $products_weight_type;
    $products_actual_weight_display = TEXT_PRODUCTS_ACTUAL_WEIGHT .  $products_actual_weight . $products_weight_type;
    $products_dim_display = TEXT_PRODUCT_DIMENSIONS . ($products_length > 0 ? TEXT_PRODUCTS_LENGTH . $products_length . $products_dim_type . ' ' : '') . ($products_width > 0 ? TEXT_PRODUCTS_WIDTH . $products_width . $products_dim_type . ' ' : '') . ($products_height > 0 ? TEXT_PRODUCTS_HEIGHT . $products_height . $products_dim_type : ''); 
    $products_diameter_display = TEXT_PRODUCTS_DIAMETER . ($products_diameter > 0 ? $products_diameter . $products_dim_type : '');
  }
  // on/off status
  $flag_show_product_info_diameter = SHOW_PRODUCT_INFO_DIAMETER;
  $flag_show_product_info_dimensions = SHOW_PRODUCT_INFO_DIMENSIONS;
  $flag_show_product_info_actual_weight = SHOW_PRODUCT_INFO_ACTUAL_WEIGHT;
  //END AUCTION SITE ATTRIBUTES

  // This should be last line of the script:
  $zco_notifier->notify('NOTIFY_HEADER_END_PRODUCT_INFO');
?>